package com.youdianstar.app.common.util

import android.annotation.SuppressLint
import android.app.Application
import java.lang.reflect.InvocationTargetException


/**
 * File: AppUtil
 * Author: 82149 Create: 2021/9/22 15:41
 * Changes (from 2021/9/22)
 * --------------------------------------------------
 * description:
 * ---------------------------------------------------
 *
 */
object AppUtil {
    private var sApplication: Application? = null

    @SuppressLint("PrivateApi")
    fun getApplication(): Application? {
        if (sApplication == null) {
            try {
                sApplication = Class.forName("android.app.ActivityThread")
                    .getMethod("currentApplication")
                    .invoke(null, null as Array<Any?>?) as Application
            } catch (e: IllegalAccessException) {
                e.printStackTrace()
            } catch (e: InvocationTargetException) {
                e.printStackTrace()
            } catch (e: NoSuchMethodException) {
                e.printStackTrace()
            } catch (e: ClassNotFoundException) {
                e.printStackTrace()
            }
        }
        return sApplication
    }

    fun setAppGlobal(mContext : Application){
        sApplication = mContext
    }
}